<template>
  <div class="browsePage">
    <div class="question">
      <el-button size="small" type="primary" @click="question">客服中心</el-button>
      <el-button size="small" type="primary" @click="userInfo">个人信息</el-button>
    </div>
    <car-carousel :carouselList="carouselList"/>
    <el-card class="cardBox">
      <el-form class="s_form" :inline="true">
        <div class="left">
          <el-form-item>
            <div class="cardName">车辆列表</div>
          </el-form-item>
        </div>
        <div class="right">
          <el-form-item>
            <el-input size="small" v-model="dataForm.carModel" placeholder="请输入关键字" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-button size="small" @click="getDataList">查询</el-button>
          </el-form-item>
        </div>
      </el-form>
      <div class="carList">
      <!-- <div class="carList" :style="'height:'+tabHeight+';'"> -->
        <div class="carItem" v-for="(item, index) in dataList" :key="index" @click="seeDetail(item)">
          <img class="carImg" :src="item.picture[0]" alt="">
          <div class="carName">{{item.carModel}}</div>
          <div class="carStock">车辆库存:{{item.stock}}</div>
          <div class="carPrice">{{item.guidePrice}}万</div>
        </div>
      </div>
      <el-pagination :current-page.sync="curPage" :page-sizes="[12]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
    </el-card>
    <car-detail ref="carDetail"/>
    <question ref="question"/>
    <user-info ref="userInfo"/>
  </div>
</template>

<script>
import carCarousel from './carComponent/carCarousel.vue'
import carDetail from './carComponent/carDetail.vue'
import question from './carComponent/question.vue'
import userInfo from './carComponent/userInfo.vue'
export default {
  components: { carDetail, carCarousel, question, userInfo },
  data () {
    return {
      dataListLoading: false,
      dataForm: {
        carModel: ''
      },
      dataList: [],
      tabHeight: '600',
      carouselList: [],
      // 分页
      curPage: 1,
      total: 0,
      limit: 12
    }
  },
  mounted () {
    this.$nextTick(() => {
      this.tabHeight = this.$getClientHeight() - 300 + 'px'
    })
  },
  activated () {
    this.getcarCarousel()
    this.getDataList()
  },
  methods: {
    // 客服中心
    question () {
      this.$refs.question.init()
    },
    // 个人信息
    userInfo () {
      this.$refs.userInfo.init()
    },
    // 查看详情
    seeDetail (item) {
      this.$refs.carDetail.init(item)
    },
    // 获取数据
    getDataList () {
      this.dataListLoading = true
      this.$http.get('/app/carinfolist', {
        params: {
          limit: this.limit,
          page: this.curPage,
          carModel: this.dataForm.carModel
        }
      }).then(({ data: res }) => {
        let { code, msg, page } = res
        console.log(code, msg, page)
        this.dataList = []
        this.total = 0
        if (code === 0 && page) {
          let { list, total } = page
          this.dataList = list && list.length ? list : []
          console.log(this.dataList)
          this.total = total
          this.dataListLoading = false
        }
        if (code !== 0) {
          this.$message.error(msg)
        }
        this.dataListLoading = false
      })
    },
    // 获取数据
    getcarCarousel () {
      this.$http.get('/app/lunbolist', {
        params: {
          limit: 100,
          page: 1
        }
      }).then(({ data: res }) => {
        let { code, msg, page } = res
        console.log(code, msg, page)
        if (code === 0) {
          this.carouselList = page.list
        }
        if (code !== 0) {
          this.$message.error(msg)
        }
      })
    },
    // 切换每页数量
    pageSizeChangeHandle (size) {
      console.log(size)
      this.limit = size
      this.curPage = 1
      this.getDataList()
    },
    // 切换页
    pageCurrentChangeHandle (curPage) {
      this.curPage = curPage
      this.getDataList()
    }
  }
}
</script>

<style lang="scss">
.browsePage {
  padding: 20px;
  .question{
    margin-bottom: 10px;
  }
  .cardBox {
    width: 100%;
    min-width: 1100px;
    background-color: rgba(255, 255, 255, 1);
    margin-top: 15px;
    text-align: center;
    .s_form {
      display: flex;
      justify-content: space-between;
      .cardName {
        font-weight: bold;
        font-size: 18px;
      }
      .s_input {
        width: 100px;
      }
    }
  }
  .carList{
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    overflow: auto;
    .carItem{
      // border: 1px solid #D8D8D8;
      border-radius: 5px;
      width: 23%;
      margin-right: 2%;
      height: 50%;
      text-align: left;
      margin-bottom: 20px;
      cursor: pointer;
      .carImg{
        width: 100%;
        height: 80%;
      }
      .carName{
        margin-top: 20px;
        margin-left: 10px;
        font-weight: blod;
        font-size: 20px;
      }
      .carStock{
        font-size: gray;
        margin-top: 10px;
        margin-left: 10px;
        font-size: 12px;
      }
      .carPrice{
        font-size: 16px;
        font-weight: bold;
        color: #FF5317;
        margin: 10px;
      }
    }
    .carItem:hover{
      border: 1px solid #fd521d;
    }
  }
}
</style>
